import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';

export default {

  //获取左边的名称
  getMessagesCenterNameList () {
    /*
    * param = {
    * notificationType：消息类型
    * 如果是欢迎消息值为guide   系统消息为global
    * }
    * */
    return httpFetch.get(config.baseUrl + `/notification/api/notification/channel?client=web`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  //消息-所有频道最新动态
  getMessagesListLatest () {
    /*
    * param = {
    * notificationType：消息类型
    * 如果是欢迎消息值为guide   系统消息为global
    * }
    * */
    return httpFetch.get(config.baseUrl + `/notification/api/notification/message/latest`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  //获取系统消息列表
  getMessagesCenterList (channelId, page, pageSize) {
    /*
    * param = {
    * }
    * */
    return httpFetch.unsafe.get(config.baseUrl + `/notification/api/notification/message/${channelId}?page=${page}&pageSize=${pageSize}&client=web`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  //获取系统消息详情
  getMessagesCenterDetail (channelId) {
    /*
    * param = {
    * id: 消息ID
    * }
    * */
    return httpFetch.unsafe.get(config.baseUrl + `/notification/api/notification/${channelId}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  //消息修改已读状态接口
  alreadyRead (channelCode) {
    return httpFetch.put(config.baseUrl + `/notification/api/notification/message/read?channelCode=${channelCode}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  //搜素消息
  searchMessage (params) {
    return httpFetch.post(config.baseUrl + `/notification/api/notification/message/detail/search`, params)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

}
